home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-23 | 76.0 KB | 2,147 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UTwistDownDocument.cp
- // ETO20 MacApp 3.3.1, MPW 3.4.1
- // Copyright ©1994-1996 Conrad Kopala
- // Twist Down Lists version 2.0a0 7/15/96
- //----------------------------------------------------------------------------------------
-
- #ifndef __UTWISTDOWNDOCUMENT__
- #include "UTwistDownDocument.h"
- #endif
-
- #ifndef __UPROGRESSINDICATORS__
- #include "UProgressIndicators.h"
- #endif
-
- #ifndef __UTWISTDOWNAPP__
- #include "UTwistDownApp.h"
- #endif
-
- #ifndef __UTWISTDOWNELEMENT__
- #include "UTwistDownElement.h"
- #endif
-
- #ifndef __UTWISTDOWNCONTROL__
- #include "UTwistDownControl.h"
- #endif
-
- #ifndef __UTWISTDOWNVIEW__
- #include "UTwistDownView.h"
- #endif
-
- //MacApp stuff
-
- #ifndef __UDEBUG__
- #include "UDebug.h" //PPC
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPRINTING__
- #include "UPrinting.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- //ToolBox stuff
- #ifndef __ERRORS__
- #include "Errors.h"
- #endif
-
- #ifndef __FILES__
- #include "Files.h"
- #endif
-
- #ifndef __FONTS__
- #include "Fonts.h"
- #endif
-
- #ifndef __QUICKDRAW__
- #include "Quickdraw.h"
- #endif
-
- #ifndef __AEREGISTRY__
- #include "AERegistry.h"
- #endif
-
- //ANSI stuff
- //None
- //----------------------------------------------------------------------------------------
- // Constants:
-
-
- //========================================================================================
- // CLASS TTwistDownDocument
- //========================================================================================
- #undef Inherited
- #define Inherited TDocument
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TTwistDownDocument, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- TTwistDownDocument::TTwistDownDocument()
- {
-
- fVolume = NULL;
- fVolumeRefNumber = 0;
- fVolumeName = gEmptyString;
- fSameVolumeNumber = 0;
- fShowInvisibleFiles = FALSE;
-
- fDependencies = NULL;
-
- fNumberOfDirectoriesToLoad = 0;
- fNumberOfFilesToLoad = 0;
- fNumberOfItemsToLoad = 0;
-
- fNumberOfDirectoriesInList = 0;
- fNumberOfFilesInList = 0;
- fNumberOfItemsInList = 0;
-
- fTwistDownView = NULL;
- fHeadOfListElement = NULL;
- fTextStyle = gApplicationStyle;
-
- fProgressBarIndicator = NULL;
- fUpdateAmount = 1;
- fProgressUpdateCounter = 0;
-
- fSearchMethod = visibleList;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::~TTwistDownDocument
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- TTwistDownDocument::~TTwistDownDocument()
- {
-
- if (fDependencies)
- fDependencies = (TSimpleDependencySpace*)(FreeIfObject(fDependencies));
-
- this -> FreeData();
-
- fHeadOfListElement = NULL; //For safety's sake, set it to NULL. It has been freed.
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::ITwistDownDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownDocument::ITwistDownDocument(TVolume* itsVolume, Boolean showInvisibleFiles)
- {
- this -> IDocument(); //IDocument contains a failure handler so any failure there will
- //get us out of ITwistDownDocument.
-
- FailInfo fi;
- Try(fi)
- {
-
- fReopenAlert = TRUE;
-
- fDependencies = new TSimpleDependencySpace; //Used for updating the progress indicator.
- fDependencies -> ISimpleDependencySpace();
-
- fVolume = itsVolume;
- CStr31 itsName;
- itsVolume -> GetName(itsName);
- this -> SetVolumeData(itsVolume -> GetVolRefNum(), itsName); //This is the most likely
- //source of a failure.
-
- fShowInvisibleFiles = showInvisibleFiles;
-
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::CloseAndFree:
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- void TTwistDownDocument::CloseAndFree()
- {
- if (fTwistDownView)
- {
- TWindow* theWindow = NULL;
- theWindow = fTwistDownView -> GetWindow();
- if (theWindow)
- gTwistDownApp -> RemoveWindowFromWindowsMenuList(theWindow);
- }
-
- Inherited::CloseAndFree();
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetDependencySpace:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- TDependencySpace* TTwistDownDocument::GetDependencySpace()
- {
- return fDependencies;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::Changed:
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- void TTwistDownDocument::Changed(ChangeID theChange, TObject* changedBy)
- {
- //The following code is from TObject::Changed. I want to avoid the TDocument::Changed method
- //because it sets fChangeCount to something other than zero which causes the application to
- //ask the user about saving the document when it is closed and TwistDownLists does not save
- //documents. I also wanted to experiment with dependencies.
-
- TDependencySpace* itsDependencySpace = this -> GetDependencySpace();
- if (itsDependencySpace)
- itsDependencySpace -> NotifierChanged(this, theChange, changedBy);
- }
-
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::FindDocument: analog of TFileBasedDocument::FindDocument
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TTwistDownDocument::FindDocument(TVolume* aVolume)
- {
- return fVolume -> IsSameVolume(aVolume);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::SetVolumeData: used by ITwistDownDocument
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownDocument::SetVolumeData(short volumeRefNumber, CStr31 volumeName)
- {
-
- FailInfo fi;
- Try(fi)
- {
- MAVolatile(HVolumeParam, pb);
-
- fVolumeRefNumber = volumeRefNumber;
- fVolumeName = volumeName;
-
- fSameVolumeNumber = gTwistDownApp -> GetNextDocumentNumber(volumeName);
-
- if (fSameVolumeNumber == 1)
- fTitle = volumeName;
- else
- {
- CStr255 docNum;
- NumToString(fSameVolumeNumber, docNum);
- fTitle = volumeName;
- fTitle += " ";
- fTitle += docNum;
- }
-
- BlockSet((Ptr) & pb, sizeof(HVolumeParam), 0x00); //For debugging fun and games, comment
- //this statement out. You will discover
- //why parameter blocks should always be
- //cleared before using them.
-
- pb.ioVRefNum = fVolumeRefNumber;
- pb.ioVolIndex = 0;
-
- FailOSErr(PBHGetVInfoSync((HParmBlkPtr)&pb));
-
- fNumberOfDirectoriesToLoad = pb.ioVDirCnt;
- fNumberOfFilesToLoad = pb.ioVFilCnt;
- fNumberOfItemsToLoad = fNumberOfDirectoriesToLoad + fNumberOfFilesToLoad;
-
- long spaceRequiredForElements = fNumberOfItemsToLoad*(gTwistDownApp -> fTDElementClassSize);
- long spaceRequiredForControls = fNumberOfDirectoriesToLoad*(gTwistDownApp -> fTDControlClassSize);
-
- if (!HaveObjectHeapSpace(spaceRequiredForElements + spaceRequiredForControls +3*1024))
- Failure(memFullErr, 0);
-
- fi.Success();
- }
- else // Recover
- {
- fi.ReSignal();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::SetUpdateAmount
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownDocument::SetUpdateAmountTo(long updateAmount)
- {
- fUpdateAmount = updateAmount;
-
- if (fProgressBarIndicator)
- fProgressBarIndicator -> SetUpdateAmountTo(fUpdateAmount);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::FreeData:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::FreeData()
- {
- fVolume = (TVolume*)(FreeIfObject(fVolume));
- fVolumeName = gEmptyString;
-
- if (fHeadOfListElement != NULL)
- this -> FreeTwistDownList(fHeadOfListElement);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::FreeTwistDownList:
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- void TTwistDownDocument::FreeTwistDownList(TTwistDownElement* twistDownElement)
- {
- TTwistDownElement* successorElement;
- TTwistDownElement* descendantElement;
-
- while (twistDownElement != NULL)
- {
-
- successorElement = twistDownElement -> GetSuccessorElement();
- descendantElement = twistDownElement -> GetDescendantElement();
-
- //Note: When the TTwistDownView is closed, the first thing it does is free all
- //the TTwistDownControls. The controls are freed before FreeTwistDownList is called.
- //The TTwistDownControl::Free() method sets the fTwistDownControl field of
- //the twistDownElement to NULL. Therefore, controls are not freed here.
-
- if (twistDownElement)
- this -> DecrementItemsInList();
-
- twistDownElement = (TTwistDownElement*)FreeIfObject(twistDownElement);
-
- if (descendantElement != NULL)
- this -> FreeTwistDownList(descendantElement);
-
- twistDownElement = successorElement;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::DoMakeViews:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownDocument::DoMakeViews(Boolean forPrinting)
- {
-
- TWindow* aTwistDownWindow = NULL;
- TTwistDownView* aTwistDownView = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- if (!forPrinting)
- {
- FailNIL(aTwistDownWindow = gViewServer -> NewTemplateWindow(kTwistDownWindowID, this));
-
- if (aTwistDownWindow != NULL)
- {
- aTwistDownView = (TTwistDownView*) (aTwistDownWindow -> FindSubView(kTwistDownViewID));
- fTwistDownView = aTwistDownView;
-
- this -> AddPrintHandlerToView(fTwistDownView);
-
- gTwistDownApp -> AddWindowToWindowsMenuList(aTwistDownWindow);
- }
-
- }
- #if qDebug
- else //forPrinting -Should never get here
- ProgramBreak("ProgramBreak -DoMakeViews forPrinting = TRUE.");
- #endif
-
- fi.Success();
- }
- else // Recover
- {
- fi.ReSignal();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::AddPrintHandlerToView:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownDocument::AddPrintHandlerToView(TView* aView)
- {
-
- TPrintHandler* aPrintHandler = (TPrintHandler*)gPrintHandler -> Clone();
-
- aPrintHandler -> fView = aView;
- aPrintHandler -> SetDefaultPrintInfo();
- this -> AttachPrintHandler(aPrintHandler);
- if (aView)
- aView -> AttachPrintHandler(aPrintHandler);
-
- // TStdPrintHandler* printHandler = new TStdPrintHandler;
- // printHandler -> IStdPrintHandler(this, aView, !kSquareDots, !kFixedSize, !kFixedSize);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::DoSetupMenus()
- {
-
- Inherited::DoSetupMenus();
-
- Enable(cSaveAs, FALSE);
- Enable(cSaveCopy, FALSE);
- Enable(cSave, FALSE);
- Enable(cRevert, FALSE);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::ReadDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- void TTwistDownDocument::ReadDocument(Boolean forPrinting)
- {
- #pragma unused forPrinting
- MAVolatileInit(OSErr, savedError, 0);
- MAVolatileInit(long, savedMessage, 0);
-
- //myOSErr is passed by reference. It is used to signal an out of memory condition when loading the list.
- OSErr myOSErr = noErr;
-
- MAVolatileInit(long, volumeDirIndex, fsRtDirID); //Must this be volatile?
- MAVolatileInit(short, indentLevel, 0); //Must this be volatile?
-
- CStr255 itsOperationString;
- GetIndString(itsOperationString, kProgressIndicatorOperationStrings, 3);
-
- CStr255 itsSubjectString = fVolumeName;
- fProgressBarIndicator = NewProgressBarIndicator(itsOperationString, itsSubjectString);
-
- this -> AddDependent(fProgressBarIndicator);
- fProgressBarIndicator -> PrepareToStart(TRUE);
-
- long barLength = fProgressBarIndicator -> GetBarLength();
-
- //The default value for fUpdateAmount is set to 1.
- //Unfortunately, if there are a lot of items to read and the progress bar is updated each time
- //an item is read, it takes a long time to populate the list. With the following if statement,
- //the update amount is adjusted so that the progress bar is updated only when enough
- //progress has been made to update it by at least one pixel. This noticibly speeds things up.
- //Comment out the following if statement and see for yourself.
-
- if (fNumberOfItemsToLoad > barLength)
- {
- long updateAmount = fNumberOfItemsToLoad/barLength;
- this -> SetUpdateAmountTo(updateAmount);
- }
-
- fProgressBarIndicator -> Start(fNumberOfItemsToLoad);
-
- FailInfo fi;
- Try(fi)
- {
-
- fHeadOfListElement = this -> BuildTwistDownList(indentLevel, volumeDirIndex, myOSErr);
-
- if (myOSErr != noErr)
- Failure(myOSErr, 0);
-
- fNumberOfFilesInList = fNumberOfItemsInList - fNumberOfDirectoriesInList;
-
- fi.Success();
- }
- else
- {
- //Save the error info until after we've gotten rid of the progress indicator.
- //Then we can signal Failure.
- savedError = fi.error;
- savedMessage = fi.message;
- if (!savedMessage)
- savedMessage = messageOpenFailed;
-
- }
-
- if (fProgressBarIndicator != NULL)
- {
- fProgressBarIndicator -> Stop();
- this -> RemoveDependent(fProgressBarIndicator);
- fProgressBarIndicator = (TProgressBarIndicator*)FreeIfObject(fProgressBarIndicator);
- }
-
- if (savedError != noErr)
- Failure(savedError, savedMessage);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::DoPostMakeViews:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownDocument::DoPostMakeViews(Boolean forPrinting)
- {
- Inherited::DoPostMakeViews(forPrinting);
-
- TWindow* aTwistDownWindow = NULL;
- aTwistDownWindow = fTwistDownView -> GetWindow();
- gTwistDownApp -> AddWindowToWindowsMenuList(aTwistDownWindow);
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::BuildTwistDownList:
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- TTwistDownElement* TTwistDownDocument::BuildTwistDownList(short indentLevel,
- long volumeDirIndex, OSErr& myOSErr)
- {
-
- HFileInfo pb;
- CStr63 fileName = gEmptyString;
- FInfo theFinderInfo;
-
- OSErr status = noErr; //status is set by PBGetCatInfoSync and signals no more files, i.e. we're done.
-
- short dirIndex;
- TTwistDownElement* previousElement;
- TTwistDownElement* firstElement;
- TTwistDownElement* thisElement;
-
- BlockSet((Ptr) & pb, sizeof(HFileInfo), 0x00);// zero-out our storage
-
- pb.ioNamePtr = fileName; //Note that pb.ioNamePtr is a pointer to fileName.
- pb.ioVRefNum = fVolumeRefNumber;
- dirIndex = 1;
-
- previousElement = NULL;
- firstElement = NULL;
- thisElement = NULL;
-
- Boolean isVisible = FALSE;
- Boolean showIt = FALSE;
-
- //The do-while loop scans the volume for all directories and files. It exits when
- // status == someError, most likely fnfErr (-43),
- // myOSErr == someError, most likely memFullErr (-108), or
- // fProgressBarIndicator -> IsStopped() == TRUE
- //
- //The status == fnfErr means the current loop is at the end of a chain in the hierarchy.
- //The myOSErr == memFullErr means we ran out of memory when MakeTwistDownElement attempted
- //to make a new twistDownElement.
- //The fProgressBarIndicator -> IsStopped() == TRUE condition means the user clicked on the
- //stop button in the progress indicator thus causing the loop to terminate early.
-
- do
- {
-
- status = noErr; //Not absolutely necessary, cleared for debugging purposes.
- fileName = gEmptyString; //Not absolutely necessary, cleared for debugging purposes.
- pb.ioFDirIndex = dirIndex;
- pb.ioDirID = volumeDirIndex; //which happens to = fsRtDirID root directory = 2
- status = PBGetCatInfoSync((CInfoPBPtr) &pb);
-
- if (status == noErr)
- {
- if (fProgressBarIndicator != NULL)
- {
- ++fProgressUpdateCounter;
- if (fProgressUpdateCounter >= fUpdateAmount)
- {
- fProgressUpdateCounter = 0;
- this -> Changed(mUpdateProgressBar, this);
- }
- }
-
- isVisible = TRUE; //Assume the item is visible.
- theFinderInfo = pb.ioFlFndrInfo;
- if ((theFinderInfo.fdFlags & kIsInvisible) == kIsInvisible)
- isVisible = FALSE;
-
- showIt = FALSE; //Assume showIt is FALSE
- if (fShowInvisibleFiles == TRUE || isVisible == TRUE)
- showIt = TRUE;
-
- if (showIt == TRUE)
- thisElement = this -> MakeTwistDownElement(previousElement,indentLevel,fileName,myOSErr);
-
- if (myOSErr == noErr)
- {
- if (firstElement == NULL)
- firstElement = thisElement;
-
- //If thisElement is a folder and it is visible, descend the hierarchy by calling ourselves recursively.
- //Store the first element in the new sub-list into thisElement's fDescendantElement.
- //Note that thisElement's fHasSubList will be TRUE even if thisElement has no descendants
- //(ie. nothing in the folder).
-
- if ((pb.ioFlAttrib & ioDirMask) == ioDirMask && thisElement != NULL && showIt == TRUE)
- {
- thisElement -> SetHasSubListFlag();
- fNumberOfDirectoriesInList++;
- thisElement -> SetDescendantElementTo(this -> BuildTwistDownList(indentLevel + 1,pb.ioDirID, myOSErr));
- }
- ++dirIndex;
- previousElement = thisElement; /* Set linkage for next file */
-
- } //end if (myOSErr == noErr)
- } //end if (status == noErr)
-
- }
- while (status == noErr && myOSErr == noErr && fProgressBarIndicator -> IsStopped() == FALSE);
-
- return (firstElement);
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::MakeTwistDownElement:
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
- TTwistDownElement* TTwistDownDocument::MakeTwistDownElement(TTwistDownElement* previousElement,
- short indentLevel,CStr63 displayedText, OSErr& myOSErr)
- {
-
- TTwistDownElement* theNewElement = NULL;
-
- FailInfo fi;
- Try(fi)
- {
-
- FailNIL(theNewElement = new TTwistDownElement);
- theNewElement -> ITwistDownElement(this, indentLevel, displayedText);
-
- /*
- //The FailHere test is commented out because it is being used in TTwistDownView::NewTwistDownControl
- //to test failure handling there when opening a disk. Probably need a second fail here flag.
-
- //Note: To properly use the FailHere type test, always initialize the object whose failure
- //you're simulating before signalling Failure(errFailHere, 0);. If you don't the failure recovery
- //won't work when it attempts to free the object.
- if (gFailHere)
- {
- CStr63 failHereText = "FailHere";
- if (failHereText == displayedText)
- Failure(errFailHere, 0);
- }
- */
-
- this -> IncrementItemsInList();
- theNewElement -> SetItemInList(fNumberOfItemsInList);
-
- if (previousElement != NULL)
- previousElement -> SetSuccessorElementTo(theNewElement);
-
- fi.Success();
- }
- // Recover. Do not ReSignal. If you do, the program will jump over any intervening
- // instances of BuildTwistDownList up to ReadDocument. As a consequence
- // fHeadOfListElement will be NULL and all the elements that were created by
- // BuildTwistDownList will not be freed. Result = a memory leak like you've
- // never seen before. Try it and see for yourself.
-
- else
- {
- theNewElement = (TTwistDownElement*)(FreeIfObject(theNewElement));
- myOSErr = fi.error;
- }
-
- return theNewElement;
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::DisposeTwistDownElement:
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- void TTwistDownDocument::DisposeTwistDownElement(TTwistDownElement* twistDownElement)
- {
- TTwistDownElement* successorElement;
- TTwistDownElement* descendantElement;
-
- while (twistDownElement != NULL)
- {
- successorElement = twistDownElement -> GetSuccessorElement();
- descendantElement = twistDownElement -> GetDescendantElement();
- TTwistDownControl* twistDownControl = twistDownElement -> GetTwistDownControl();
- if (twistDownControl != NULL)
- {
- fTwistDownView -> RemoveSubView(twistDownControl);
- twistDownControl = (TTwistDownControl*)FreeIfObject(twistDownControl);
-
- //Note: The TTwistDownControl::Free() method sets the fTwistDownControl field of
- //the twistDownElement to NULL;
-
- }
-
- twistDownElement = (TTwistDownElement*)FreeIfObject(twistDownElement);
-
- if (descendantElement != NULL)
- DisposeTwistDownElement(descendantElement);
-
- twistDownElement = successorElement;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::CountVisibleElements:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- long TTwistDownDocument::CountVisibleElements(TTwistDownElement* twistDownElement)
- {
- long result = 0;
-
- while (twistDownElement != NULL)
- {
- ++result;
- if (twistDownElement -> TestShowSubListFlag())
- result += this -> CountVisibleElements(twistDownElement -> GetDescendantElement());
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- return result;
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetTwistDownElementAt:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::GetTwistDownElementAt(short anItem, TTwistDownElement* startingTwistDownElement,
- TTwistDownElement** currentTwistDownElement, short &rowNumber)
- {
- MAVolatileInit(TTwistDownElement*, twistDownElement, NULL);
-
- twistDownElement = startingTwistDownElement;
-
- while (twistDownElement != NULL && rowNumber != anItem)
- {
- ++rowNumber;
- *currentTwistDownElement = twistDownElement;
-
- if (twistDownElement -> TestShowSubListFlag())
- {
- this -> GetTwistDownElementAt(anItem, twistDownElement -> GetDescendantElement(),
- currentTwistDownElement, rowNumber);
-
- }
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetTwistDownElementRowNumber:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::GetTwistDownElementRowNumber(TTwistDownElement* startingTwistDownElement,
- TTwistDownElement* targetTwistDownElement,
- TTwistDownElement** currentTwistDownElement, short &rowNumber)
- {
- MAVolatileInit(TTwistDownElement*, twistDownElement, NULL);
-
- twistDownElement = startingTwistDownElement;
-
- while (twistDownElement != NULL && *currentTwistDownElement != targetTwistDownElement)
- {
- ++rowNumber;
- *currentTwistDownElement = twistDownElement;
-
- if (twistDownElement -> TestShowSubListFlag())
- {
- this -> GetTwistDownElementRowNumber(twistDownElement -> GetDescendantElement(), targetTwistDownElement,
- currentTwistDownElement, rowNumber);
-
- }
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetHeadOfList:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TTwistDownElement* TTwistDownDocument::GetHeadOfList()
- {
- return fHeadOfListElement;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::ExpandElement:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::ExpandElement(TTwistDownElement* twistDownElementToExpand)
- {
- OSErr myOSErr = noErr; //passed by reference to AddTwistDownControls.
- TTwistDownElement* currentTwistDownElement = NULL;
- short targetRowNumber = 0;
- short rowNumber = 0;
-
- rowNumber = 0;
- this -> GetTwistDownElementRowNumber(fHeadOfListElement, twistDownElementToExpand,
- ¤tTwistDownElement, rowNumber);
-
- targetRowNumber = rowNumber + 1; //I want to insert rows in front of the row following the twistDownElementToExpand.
- //targetRowNumber may 'point' to a row that doesn't exist. For example, the row
- //following the last twistDownElement. I let BuildVisibleList take care of
- //this situation.
-
- twistDownElementToExpand -> SetShowSubListFlag();
-
- FailInfo fi;
- Try(fi)
- {
- rowNumber = 0;
- fTwistDownView -> AddTwistDownControls(fHeadOfListElement, rowNumber, myOSErr); //This puts in the new controls
- //with the proper locations.
-
- if (myOSErr != noErr)
- Failure(myOSErr, 0);
-
- rowNumber = 0;
- fTwistDownView -> UpdateTwistDownControlLocations(fHeadOfListElement, rowNumber); //This updates the locations
- //of all the controls.
-
- myOSErr = fTwistDownView -> BuildVisibleList(targetRowNumber); //Inserts rows as required in front of
- //targetRowNumber unless it is beyond the end
- //of the currently displayed list. In that
- //case, the rows are inserted last.
-
- //Ordinarily, I would test myOSErr to make sure we hadn't failed because we attempted to add
- //too many rows to TTwistDownView. However, we always call TTwistDownElement::CouldExpandElement()
- //in either TTwistDownControl::DoMouseUp or TTwistDownElement::DoScriptCommand and if too many
- //rows would be added, we fail there rather than letting the operation get this far. The only
- //failure that can occur in this method is an out of memory condition while adding new TTwistDownControls.
- //if (myOSErr == errTooManyRows)
- // Failure(errTooManyRows, msgTooManyRows);
-
- fTwistDownView -> ResizeTwistDownViewRows(); //Adjusts the size of the view to accomodate the exact number of rows.
- fi.Success();
- }
- else
- {
- twistDownElementToExpand -> ClearShowSubListFlag();
- TTwistDownElement* descendantTwistDownElement = twistDownElementToExpand -> GetDescendantElement();
- fTwistDownView -> DeleteTwistDownControls(descendantTwistDownElement);
- fi.ReSignal();
- }
- } //TTwistDownDocument::ExpandElement
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::CollapseElement:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::CollapseElement(TTwistDownElement* twistDownElementToCollapse)
- {
- OSErr myOSErr = noErr;
- TTwistDownElement* descendantTwistDownElement = NULL;
- TTwistDownElement* currentTwistDownElement = NULL;
- short targetRowNumber = 0;
- short rowNumber = 0;
-
- rowNumber = 0;
- this -> GetTwistDownElementRowNumber(fHeadOfListElement, twistDownElementToCollapse,
- ¤tTwistDownElement, rowNumber);
- targetRowNumber = rowNumber + 1;
-
- descendantTwistDownElement = twistDownElementToCollapse -> GetDescendantElement();
- fTwistDownView -> DeleteTwistDownControls(descendantTwistDownElement);
-
- twistDownElementToCollapse -> ClearShowSubListFlag();
-
- rowNumber = 0;
- fTwistDownView -> UpdateTwistDownControlLocations(fHeadOfListElement, rowNumber);
-
- myOSErr = fTwistDownView -> BuildVisibleList(targetRowNumber); //myOSErr isn't tested because
- //a tooManyRows error should
- //have been caught before we
- //ever get here.
- fTwistDownView -> ResizeTwistDownViewRows();
-
- } //TTwistDownDocument::CollapseElement:
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::SetShowSubListFlags: Used by ExpandAll
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- //When the Expand All command is executed, all fShowSubList flags of all twistDownElements
- //are set to TRUE.
- void TTwistDownDocument::SetShowSubListFlags(TTwistDownElement* twistDownElement)
- {
- while (twistDownElement != NULL)
- {
- if (twistDownElement -> TestHasSubListFlag()) //Only select those twistDownElements
- //that have a sublist (have a descendant element)
- {
- twistDownElement -> SetShowSubListFlag(); //This sets fOldShowSubList to the current
- //value of fShowSubList and then sets
- //fShowSubList to TRUE.
-
- this -> SetShowSubListFlags(twistDownElement -> GetDescendantElement());
- }
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::ClearShowSubListFlags: Used by CollapseAll
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- //When the Collapse All command is executed, the fShowSubList flag of all twistDownElements
- //is set to FALSE. At present, fOldShowSublist is set to the current value of fShowSubList
- //before fShowSubList is set to FALSE. I probably should set fOldShowSubList to FALSE.
-
- void TTwistDownDocument::ClearShowSubListFlags(TTwistDownElement* twistDownElement)
- {
- while (twistDownElement != NULL)
- {
- if (twistDownElement -> TestHasSubListFlag()) //Only select those twistDownElements
- //that have a sublist (have a descendant element)
- {
- twistDownElement -> ClearShowSubListFlag();
- this -> ClearShowSubListFlags(twistDownElement -> GetDescendantElement());
- }
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::RestoreShowSubListFlags: Used to recover from a failed ExpandAll
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- //If the execution of ExpandAll should fail (out of memory), we must recover. To do that
- //we must restore the value of fShowSubList to its previous value. This method restores
- // fShowSubList to the value of fOldShowSublist and then sets fOldShowSubList to FALSE.
-
- void TTwistDownDocument::RestoreShowSubListFlags(TTwistDownElement* twistDownElement)
- {
- while (twistDownElement != NULL)
- {
- if (twistDownElement -> TestHasSubListFlag())
- {
- twistDownElement -> RestoreShowSubListFlag();
- this -> RestoreShowSubListFlags(twistDownElement -> GetDescendantElement());
- }
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::CollapseAll: used by TCollapseAllCommand::DoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- //Note:
- void TTwistDownDocument::CollapseAll()
- {
- OSErr myOSErr = noErr;
- short rowNumber = 0;
-
- fTwistDownView -> DeleteTwistDownControls(fHeadOfListElement); //First delete existing controls unless
- //twistDownElement -> fIndentLevel == 0.
- //
-
- this -> ClearShowSubListFlags(fHeadOfListElement); //The controls must be deleted before the
- //fShowSubList flags are cleared. If the
- //flags are cleared first, DeleteTwistDownControls
- //will not traverse the list because it uses
- //fShowSubList to descend the hierarchy.
- //Consequently, controls will not be deleted.
-
- rowNumber = 0;
- fTwistDownView -> UpdateTwistDownControlLocations(fHeadOfListElement, rowNumber);
-
- rowNumber = 1;
- myOSErr = fTwistDownView -> BuildVisibleList(rowNumber);
-
- fTwistDownView -> ResizeTwistDownViewRows();
-
- } //TTwistDownDocument::CollapseAll
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::InstallTextStyle:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TTwistDownDocument::InstallTextStyle(const TextStyle& itsTextStyle)
- {
- fTextStyle = itsTextStyle;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::UpdateTwistDownElements: called by TTwistDownView::DoChangeWritingDirection
- // TTwistDownView::DoChangeTextStyle
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::UpdateTwistDownElements(TTwistDownElement* twistDownElement, short &rowNumber)
- {
-
- while (twistDownElement != NULL)
- {
- ++rowNumber;
- TTwistDownControl* twistDownControl = twistDownElement -> GetTwistDownControl();
- if (twistDownControl != NULL)
- {
- twistDownControl -> InstallTextStyle(fTextStyle, kDontRedraw); //In another time and place it
- //might be necessary that the
- //proper TextStyle be installed so
- //just do it so you don't forget
- //about it.
- twistDownControl -> UpdateControlSizeTo(); //sets fSize of twistDownControl
- twistDownControl -> UpdateControlLocationTo(rowNumber); //sets fCoordinatesAreInvalid
-
- }
-
- if (twistDownElement -> TestShowSubListFlag())
- this -> UpdateTwistDownElements(twistDownElement -> GetDescendantElement(), rowNumber);
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::CalculateColWidthParams: called by TTwistDownView::CalculateColumnWidth
- //----------------------------------------------------------------------------------------
- //This routine scans the visible list and returns the greatest value for the indentLevel it
- //finds along with the width of the largest twistDownElement -> fDisplayedText. The intent
- //is to use that information to intelligently set the column width in the twistDownView.
- //It has been tested but is not currently being used.
- #pragma segment ARes
- void TTwistDownDocument::CalculateColWidthParams(TTwistDownElement* twistDownElement, short& maxIndentLevel,
- short& maxTextWidth)
- {
- while (twistDownElement != NULL)
- {
- short indentLevel = twistDownElement -> GetIndentLevel();
- if (indentLevel > maxIndentLevel)
- maxIndentLevel = indentLevel;
-
- CStr63 displayedText = gEmptyString;
- twistDownElement -> GetDisplayedText(displayedText);
- short stringWidth = StringWidth(displayedText);
- if (stringWidth > maxTextWidth)
- maxTextWidth = stringWidth;
-
- if (twistDownElement -> TestShowSubListFlag())
- this -> CalculateColWidthParams(twistDownElement -> GetDescendantElement(), maxIndentLevel, maxTextWidth);
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::IncrementItemsInList:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
- void TTwistDownDocument::IncrementItemsInList()
- {
- fNumberOfItemsInList++;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::DecrementItemsInList:
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- void TTwistDownDocument::DecrementItemsInList()
- {
- fNumberOfItemsInList--;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetNumberOfDirectoriesInList:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- long TTwistDownDocument::GetNumberOfDirectoriesInList()
- {
- return fNumberOfDirectoriesInList;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetNumberOfItemsInList:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- long TTwistDownDocument::GetNumberOfItemsInList()
- {
- return fNumberOfItemsInList;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::DoScriptCommand: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownDocument::DoScriptCommand(CommandNumber aCommandNumber, TAppleEvent* message, TAppleEvent* reply)
- {
-
- switch (aCommandNumber)
- {
- case cExpandAll:
- {
- //If fCouldExpandAll == TRUE then we most certainly will not be adding too many rows.
- //However, TExpandAllCommand::DoIt also checks - overkill???
- if (fTwistDownView -> fCouldExpandAll)
- {
- long objectHeapSpaceRequired = long((this -> GetNumberOfDirectoriesInList()
- - fTwistDownView -> GetNumberOfControls())*(gTwistDownApp -> fTDControlClassSize));
-
- Boolean haveHeapSpace = HaveObjectHeapSpace(objectHeapSpaceRequired + 3*1024);
-
- if (haveHeapSpace)
- {
- TExpandAllCommand* anExpandAllCommand = new TExpandAllCommand;
- anExpandAllCommand -> IExpandAllCommand(this,fTwistDownView,
- message -> fMessage, reply -> fMessage);
-
- this -> PostCommand(anExpandAllCommand);
- }
- else
- Failure(memFullErr, 0);
- }
- else
- FailOSErr(errListAlreadyExpanded);
- }
- break;
-
- case cCollapseAll:
- {
- if (fTwistDownView -> fCouldCollapseAll)
- {
- //Because we don't want this to fail for out of memory reasons,
- //allocate it from temporary memory. //PGMacApp 550
- Boolean oldTemp = TemporaryAllocation(TRUE);
- Boolean oldArrayPerm = AllocateObjectsFromPerm(FALSE);
- TCollapseAllCommand* aCollapseAllCommand = new TCollapseAllCommand;
- aCollapseAllCommand -> ICollapseAllCommand(this, fTwistDownView,
- message -> fMessage, reply -> fMessage);
-
- this -> PostCommand(aCollapseAllCommand);
- oldArrayPerm = AllocateObjectsFromPerm(oldArrayPerm);
- oldTemp = TemporaryAllocation(oldTemp);
- }
- else
- FailOSErr(errListAlreadyCollapsed);
- }
- break;
-
- default:
- {
- Inherited::DoScriptCommand(aCommandNumber, message, reply);
- }
- break;
- }
-
- }
- //----------------------------------------------------------------------------------------
- //Note: The following four methods:
- //
- //GetTwistDownElementByName,
- //GetTwistDownElementByIndex,
- //GetVisibleTwistDownElementByName, and
- //GetVisibleTwistDownElementByIndex
- //
- //would not exist if Scripting were not supported. Each twistDownElement in the list has
- //an absolute position established when the list is read. However, the whole list is not
- //always visible to the user. Now, if a user were to expand a twistDownElement that is not
- //visible, the view would not change and he might be expecting a change. This could cause
- //confusion. One solution would be to make it visible by expanding all the twistDownElements
- //in the chain above the target twistDownElement. At this point, I don't like that idea.
- //The solution chosen here, is to allow the user to specify a search method of either just
- //the visible list or the whole list. The default is to search only the visible list.
- //
- //If the user chooses to search the whole list, when expanding or collapsing a twistDownElement,
- //and the twistDownElement is not visible, the expansion or collapse of the element takes
- //place but is not visible to the user at that time. However, if the user then expands
- //all the elements in the chain above the target twistDownElement, the effect will then be
- //seen (revealed).
- //
- //This situation clearly illustrates a situation where scripting support must go beyond the
- //capabilities of the user interface. In other words, it is not possible for the user to
- //expand or collapse a twistDownElement that is not visible from the user interface.
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetTwistDownElementByName: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::GetTwistDownElementByName(TTwistDownElement* startingTwistDownElement,
- TTwistDownElement** currentTwistDownElement, CStr63 &theName, Boolean &foundIt)
- {
- MAVolatileInit(TTwistDownElement*, twistDownElement, NULL);
-
- twistDownElement = startingTwistDownElement;
-
- while (twistDownElement != NULL && foundIt == FALSE)
- {
-
- *currentTwistDownElement = twistDownElement;
- CStr63 aString = gEmptyString;
- twistDownElement -> GetDisplayedText(aString);
- if (aString == theName)
- foundIt = TRUE;
-
- if (twistDownElement -> GetDescendantElement() != NULL)
- this -> GetTwistDownElementByName(twistDownElement -> GetDescendantElement(), currentTwistDownElement,
- theName, foundIt);
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetTwistDownElementByIndex: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::GetTwistDownElementByIndex(short desiredIndex,
- TTwistDownElement* startingTwistDownElement,
- TTwistDownElement** currentTwistDownElement,
- short &elementCounter)
- {
- MAVolatileInit(TTwistDownElement*, twistDownElement, NULL);
-
- twistDownElement = startingTwistDownElement;
-
- while (twistDownElement != NULL && elementCounter != desiredIndex)
- {
- ++elementCounter;
- *currentTwistDownElement = twistDownElement;
-
- if (twistDownElement -> GetDescendantElement() != NULL)
- this -> GetTwistDownElementByIndex(desiredIndex, twistDownElement -> GetDescendantElement(),
- currentTwistDownElement, elementCounter);
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetVisibleTwistDownElementByName: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::GetVisibleTwistDownElementByName(TTwistDownElement* startingTwistDownElement,
- TTwistDownElement** currentTwistDownElement, CStr63 &theName, Boolean &foundIt)
- {
- MAVolatileInit(TTwistDownElement*, twistDownElement, NULL);
-
- twistDownElement = startingTwistDownElement;
-
- while (twistDownElement != NULL && foundIt == FALSE)
- {
-
- *currentTwistDownElement = twistDownElement;
- CStr63 aString = gEmptyString;
- twistDownElement -> GetDisplayedText(aString);
- if (aString == theName)
- foundIt = TRUE;
-
- if (twistDownElement -> GetDescendantElement() != NULL && twistDownElement -> TestShowSubListFlag())
- this -> GetVisibleTwistDownElementByName(twistDownElement -> GetDescendantElement(), currentTwistDownElement,
- theName, foundIt);
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetVisibleTwistDownElementByIndex: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- void TTwistDownDocument::GetVisibleTwistDownElementByIndex(short desiredIndex, TTwistDownElement* startingTwistDownElement,
- TTwistDownElement** currentTwistDownElement, short &elementCounter)
- {
- MAVolatileInit(TTwistDownElement*, twistDownElement, NULL);
-
- twistDownElement = startingTwistDownElement;
-
- while (twistDownElement != NULL && elementCounter != desiredIndex)
- {
- ++elementCounter;
- *currentTwistDownElement = twistDownElement;
-
- if (twistDownElement -> GetDescendantElement() != NULL && twistDownElement -> TestShowSubListFlag())
- this -> GetVisibleTwistDownElementByIndex(desiredIndex, twistDownElement -> GetDescendantElement(),
- currentTwistDownElement, elementCounter);
-
- twistDownElement = twistDownElement -> GetSuccessorElement();
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetObjectProperty: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- Boolean TTwistDownDocument::GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType)
- {
- // Return properties for the twistDownView
-
- Boolean hasProperty = TRUE;
-
- FailInfo fi;
- Try(fi)
- {
- switch (whichProperty)
- {
-
- case pFontName:
- CStr255 theFontName;
- short theFontNum = fTextStyle.tsFont;
- GetFontName(theFontNum, theFontName);
- thePropertyValue.PutString(theFontName);
- break;
-
- case pPointSize:
- long itsSize = (long)fTextStyle.tsSize;
- thePropertyValue.PutLong(itsSize);
- break;
-
- case pSearchMethod:
- {
- DescType theSearchMethod;
-
- if (fSearchMethod == visibleList)
- theSearchMethod = kAEVisibleList;
- else
- theSearchMethod = kAEWholeList;
-
- thePropertyValue.PutEnum(theSearchMethod);
- }
- break;
-
- case pNumFolders:
- thePropertyValue.PutLong(fNumberOfDirectoriesInList);
- break;
-
- case pNumFiles:
- thePropertyValue.PutLong(fNumberOfFilesInList);
- break;
-
- case pNumItems:
- thePropertyValue.PutLong(fNumberOfItemsInList);
- break;
-
- default:
- hasProperty = Inherited::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- break;
- }
- fi.Success();
- }
- else
- {
- // we failed while trying to get the property
- hasProperty = FALSE;
-
- // Don't ReSignal
- }
- return hasProperty;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetSetPropertyInfo: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownDocument::GetSetPropertyInfo(DescType whichProperty,CommandNumber& cmdNum,
- Boolean& canUndo,Boolean& causesChange,TCommandHandler* &theContext)
- {
-
- switch(whichProperty)
- {
-
- case pFontName:
- cmdNum = cChangeFont;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pPointSize:
- cmdNum = cChangeFontSize;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- case pSearchMethod:
- cmdNum = cSetSearchMethod;
- canUndo = FALSE;
- causesChange = FALSE;
- theContext = this;
- break;
-
- default:
- Inherited::GetSetPropertyInfo(whichProperty, cmdNum, canUndo, causesChange, theContext);
- break;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::SetObjectProperty: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
- void TTwistDownDocument::SetObjectProperty(const CAEDesc& thePropertyValue,DescType whichProperty)
- {
- //I'm ambivalent about whether it makes sense to allow a script to change the font or its size,
- //if the list is empty. We wouldn't allow it from the menu. For the sake of argument, let's
- //allow it here and not allow it in TTwistDownView::SetObjectProperty.
-
- long numberOfItemsInList = numberOfItemsInList = this -> GetNumberOfItemsInList();
-
- switch (whichProperty)
- {
-
- case pFontName:
- CStr255 newFontName;
- thePropertyValue.GetString(newFontName,255);
- // if (numberOfItemsInList > 0)
- fTwistDownView -> DoChangeFont(newFontName);
- break;
-
- case pPointSize:
- short newFontSize = 0;
- newFontSize = (short)thePropertyValue.GetLong();
- // if (numberOfItemsInList > 0)
- fTwistDownView -> DoChangeFontSize(newFontSize);
- break;
-
- case pSearchMethod:
- {
- DescType theSearchMethod = thePropertyValue.GetEnum();
-
- if (theSearchMethod == kAEVisibleList)
- fSearchMethod = visibleList;
- else
- fSearchMethod = wholeList;
- }
- break;
-
- case pNumFolders:
- case pNumFiles:
- case pNumItems:
- FailOSErr(errAECantSetReadOnly);
- break;
-
- default:
- Inherited::SetObjectProperty(thePropertyValue, whichProperty);
- break;
- }
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetIndContainedObject: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment OSLDispatchRes
-
- MScriptableObject* TTwistDownDocument::GetIndContainedObject(DescType desiredType,long index)
- {
-
- MScriptableObject *indexedObject;
-
- switch(desiredType)
- {
- case cTwistDownView:
- {
- TTwistDownView* indexedTwistDownView = fTwistDownView;
- indexedObject = indexedTwistDownView;
- }
- break;
-
- case cTwistDownElement:
- {
-
-
- TTwistDownElement* currentTwistDownElement = NULL;
- short theIndex = (short)index;
- short elementCounter = 0;
-
- if (fSearchMethod == visibleList)
- this -> GetVisibleTwistDownElementByIndex(theIndex, fHeadOfListElement,
- ¤tTwistDownElement, elementCounter);
- else
- //Note: I should be able to do this using the fItemInList field of TTwistDownElement
- //instead of counting.
- this -> GetTwistDownElementByIndex(theIndex, fHeadOfListElement,
- ¤tTwistDownElement, elementCounter);
-
- indexedObject = currentTwistDownElement;
- }
- break;
-
- default:
- {
- indexedObject = Inherited::GetIndContainedObject(desiredType, index);
- }
- break;
- }
-
- return indexedObject;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::GetContainedObject: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment OSLDispatchRes
- MScriptableObject* TTwistDownDocument::GetContainedObject(DescType desiredType,DescType selectionForm,
- const CAEDesc& selectionData)
- {
-
- MScriptableObject * result = NULL;
-
- if (desiredType == cTwistDownView)
- {
- TTwistDownView* resultTwistDownView = fTwistDownView;
- result = resultTwistDownView;
- }
-
- else if (desiredType == cTwistDownElement)
- {
-
- if (selectionForm == formName)
- {
- CStr255 theName = gEmptyString;
- selectionData.GetString(theName);
- TTwistDownElement* currentTwistDownElement = NULL;
- Boolean foundIt = FALSE;
-
- if (fSearchMethod == visibleList)
- this -> GetVisibleTwistDownElementByName(fHeadOfListElement, ¤tTwistDownElement,
- (CStr63 &)theName, foundIt);
- else
- this -> GetTwistDownElementByName(fHeadOfListElement, ¤tTwistDownElement,
- (CStr63 &)theName, foundIt);
-
- if (foundIt == FALSE)
- currentTwistDownElement = NULL;
-
- result = currentTwistDownElement;
- }
- else if (selectionForm == formAbsolutePosition)
- {
- //Note: I should be able to do this using the fItemInList field of TTwistDownElement
- //instead of counting.
- TTwistDownElement* currentTwistDownElement = NULL;
- long index = selectionData.GetLong();
- short theIndex = (short)index;
-
- if (theIndex <= fNumberOfItemsInList)
- {
- short elementCounter = 0;
-
- if (fSearchMethod == visibleList)
- this -> GetVisibleTwistDownElementByIndex(theIndex, fHeadOfListElement,
- ¤tTwistDownElement, elementCounter);
- else
- this -> GetTwistDownElementByIndex(theIndex, fHeadOfListElement,
- ¤tTwistDownElement, elementCounter);
- }
-
- result = currentTwistDownElement;
-
- }
- }
-
- else
- result = Inherited::GetContainedObject(desiredType, selectionForm, selectionData);
-
- return result;
- }
- //----------------------------------------------------------------------------------------
- // TTwistDownDocument::CountContainedObjects:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- long TTwistDownDocument::CountContainedObjects(DescType desiredType)
- {
-
- long result = 0;
-
- switch (desiredType)
- {
- case cTwistDownView:
- {
- result = 1;
- }
- break;
-
- case cTwistDownElement:
- {
- result = fNumberOfItemsInList;
- }
- break;
-
- default:
- {
- result = Inherited::CountContainedObjects(desiredType);
- }
- break;
- }
-
- return result;
- }
- //========================================================================================
- // CLASS TExpandAllCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TServerCommand
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TExpandAllCommand, Inherited);
- //----------------------------------------------------------------------------------------
- // TExpandAllCommand::TExpandAllCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TExpandAllCommand::TExpandAllCommand()
- {
- fTwistDownView = NULL;
- fTwistDownDocument = NULL;
-
- fOldNumberOfExpandedControls = 0;
- fOldNumberOfCollapsedControls = 0;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TExpandAllCommand::~TExpandAllCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TExpandAllCommand::~TExpandAllCommand()
- {
-
- fTwistDownView = NULL;
- fTwistDownDocument = NULL;
-
- fOldNumberOfExpandedControls = 0;
- fOldNumberOfCollapsedControls = 0;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TExpandAllCommand::IExpandAllCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TExpandAllCommand::IExpandAllCommand(TTwistDownDocument* twistDownDocument, TCommandHandler* itsContext)
- {
- this -> IServerCommand(cExpandAll,itsContext,kCantUndo, kDoesNotCauseChange,NULL);
-
- fTwistDownDocument = twistDownDocument;
- fTwistDownView = twistDownDocument -> fTwistDownView;
-
- fOldNumberOfExpandedControls = fTwistDownView -> GetNumberOfExpandedControls();
- fOldNumberOfCollapsedControls = fTwistDownView -> GetNumberOfCollapsedControls();
-
- }
-
- //----------------------------------------------------------------------------------------
- // TExpandAllCommand::IExpandAllCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TExpandAllCommand::IExpandAllCommand(TTwistDownDocument* twistDownDocument, TCommandHandler* itsContext,
- const AppleEvent& itsMessage, const AppleEvent& itsReply)
- {
- fSuspendTheEvent = TRUE; //For debugging fun and games, comment this out. Everything
- //will work fine until you encounter low memory conditions
- //and fail. Then all bets are off. Note that it must be set
- //before IServerCommand is called.
-
- this -> IServerCommand(cExpandAll,itsContext,kCantUndo, kDoesNotCauseChange,NULL,itsMessage,itsReply);
-
-
-
- fTwistDownDocument = twistDownDocument;
- fTwistDownView = twistDownDocument -> fTwistDownView;
-
- fOldNumberOfExpandedControls = fTwistDownView -> GetNumberOfExpandedControls();
- fOldNumberOfCollapsedControls = fTwistDownView -> GetNumberOfCollapsedControls();
-
- }
-
- //----------------------------------------------------------------------------------------
- // TExpandAllCommand::MakeAppleEvent: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment ACommandRes
- TAppleEvent* TExpandAllCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent*, theExpandAllEvent, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- theExpandAllEvent = new TAppleEvent;
- theExpandAllEvent -> IAppleEvent(kAETwistDownListsSuite, kAEExpandAllID,gServerAddress, kAENoReply);
- {
- CTempDesc directObjectDesc;
- if (gAppleEventRouting == routeToDoc)
- fTwistDownDocument -> MakeObjectSpecifier(directObjectDesc, fTwistDownDocument -> GetSpecifierForm());
- else if (gAppleEventRouting == routeToView)
- fTwistDownView -> MakeObjectSpecifier(directObjectDesc, fTwistDownView -> GetSpecifierForm());
-
- theExpandAllEvent -> WriteParameter(keyDirectObject, directObjectDesc);
- }
- fi.Success();
- }
- else // Recover
- {
- theExpandAllEvent = (TAppleEvent *)FreeIfObject(theExpandAllEvent);
- fi.ReSignal();
- }
-
- return theExpandAllEvent;
-
- }
- //----------------------------------------------------------------------------------------
- // TExpandAllCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TExpandAllCommand::DoIt()
- {
- OSErr myOSErr = noErr;
- TTwistDownElement* headOfListElement = fTwistDownDocument -> GetHeadOfList();
- short rowNumber = 0;
-
- FailInfo fi;
- Try(fi)
- {
- //Note: The following test is here only to support scripting. DoMenuCommand support does not
- //require this test because the fCouldExpandAll flag will be FALSE if the number of items
- //in the list exceeds the capacity of TTextListView. In other words, if there are too many
- //rows to display, you can't get here from the menu and you shouldn't be able to get here
- //from DoScriptCommand either because DoScriptCommand tests fCouldExpandAll before even
- //making the TExpandAllCommand.
- if (fTwistDownDocument -> GetNumberOfItemsInList() <= (long)kMaxNumberOfItemsToDisplay)
- {
- //Step 1: For all TTwistDownElements for which fHasSubList is TRUE, set fShowSubList to TRUE.
- fTwistDownDocument -> SetShowSubListFlags(headOfListElement);
-
- //Step 2: Make and add the new controls to the twistDownView (with the proper locations.)
- rowNumber = 0;
-
- fTwistDownView -> AddTwistDownControls(headOfListElement, rowNumber, myOSErr);
-
- if (myOSErr != noErr)
- Failure(myOSErr, 0);
-
- //Step 3: Uupdate the locations of all the controls.
- rowNumber = 0;
- fTwistDownView -> UpdateTwistDownControlLocations(headOfListElement, rowNumber);
-
- //Step 4: Insert rows as required in front of rowNumber unless it
- //is beyond the end of the currently displayed list. In that
- //case, the rows are inserted last.
- rowNumber = 1;
- myOSErr = fTwistDownView -> BuildVisibleList(rowNumber);
-
- //Step 5: Adjust the size of the view to accomodate the exact number of rows.
- fTwistDownView -> ResizeTwistDownViewRows();
-
- //just set fNumberOfExpandedControls to fNumberOfDirectoriesInList
- //and set fNumberOfCollapsedControls to 0.
- fTwistDownView -> SetCantExpandAll(); //Will cause the cExpandAll command to be disabled.
- }
- else
- {
- myOSErr = errTooManyRows;
- Failure(errTooManyRows, msgTooManyRows);
- }
-
- fi.Success();
- }
- else
- { //Situation: For all twistDownElements for which fHasSubList if TRUE, fOldShowSubList
- //has been set to fShowSubList and then fShowSubList has been set to TRUE. New twistDownControls
- //may have been added to the twistDownView. If failure occurred on the first attempt
- //to AddTwistDownControls, no new twistDownControls will have been added. The failure
- //handler in AddTwistDownControls will have freed the offending control.
- //
- //To recover, we need to remove twistDownControls from from all twistDownElements
- //whose fOldShowSubList flag is set to FALSE. Then fShowSubList must be set to the
- //value of fOldShowSubList and then fOldShowSubList must be set to FALSE.
-
- //There are two kinds of errors that bring us here. In the case of errTooManyRows, nothing
- //has been done to the list and we skip over the following steps and ReSignal. In the other case
- //An out of memory condition may be signaled by AddTwistDownControls. In that case the prior state
- //of the list must be restored.
- if (myOSErr != errTooManyRows)
- {
- //Step 1: Remove the unwanted twistDownControls. A failure in AddTwistDownControls will have
- //freed the offending twistDownControl before we get here.
-
- fTwistDownView -> RestoreTwistDownControls(headOfListElement);
-
- //Step 2: Restore the fShowSubList flags to their previous setting and set fOldShowSubList
- //to FALSE.
-
- fTwistDownDocument -> RestoreShowSubListFlags(headOfListElement);
-
- fTwistDownView -> SetNumberOfExpandedControlsTo(fOldNumberOfExpandedControls);
- fTwistDownView -> SetNumberOfCollapsedControlsTo(fOldNumberOfCollapsedControls);
- fTwistDownView -> SetTheCouldFlags();
- }
- fi.ReSignal();
- }
- }
- //========================================================================================
- // CLASS TCollapseAllCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TServerCommand
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TCollapseAllCommand, Inherited);
- //----------------------------------------------------------------------------------------
- // TCollapseAllCommand::TCollapseAllCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TCollapseAllCommand::TCollapseAllCommand()
- {
- fTwistDownDocument = NULL;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TCollapseAllCommand::~TCollapseAllCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TCollapseAllCommand::~TCollapseAllCommand()
- {
- fTwistDownDocument = NULL;
- fTwistDownView = NULL;
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TCollapseAllCommand::ICollapseAllCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TCollapseAllCommand::ICollapseAllCommand(TTwistDownDocument* twistDownDocument, TCommandHandler* itsContext)
- {
- this -> IServerCommand(cCollapseAll,itsContext,kCantUndo, kDoesNotCauseChange,NULL);
-
- fTwistDownDocument = twistDownDocument;
- fTwistDownView = twistDownDocument -> fTwistDownView;
- }
- //----------------------------------------------------------------------------------------
- // TCollapseAllCommand::ICollapseAllCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TCollapseAllCommand::ICollapseAllCommand(TTwistDownDocument* twistDownDocument, TCommandHandler* itsContext,
- const AppleEvent& itsMessage, const AppleEvent& itsReply)
- {
- fSuspendTheEvent = TRUE; //For debugging fun and games, comment this out. Everything
- //will work fine until you encounter low memory conditions
- //and fail. Then all bets are off. Note that it must be set
- //before IServerCommand is called.
-
- this -> IServerCommand(cCollapseAll,itsContext,kCantUndo, kDoesNotCauseChange,NULL,itsMessage,itsReply);
-
- fTwistDownDocument = twistDownDocument;
- fTwistDownView = twistDownDocument -> fTwistDownView;
- }
- //----------------------------------------------------------------------------------------
- // TCollapseAllCommand::MakeAppleEvent: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment ACommandRes
- TAppleEvent* TCollapseAllCommand::MakeAppleEvent()
- {
-
- MAVolatileInit(TAppleEvent*, theCollapseAllEvent, NULL);
-
- FailInfo fi;
- Try(fi)
- {
-
- theCollapseAllEvent = new TAppleEvent;
- theCollapseAllEvent -> IAppleEvent(kAETwistDownListsSuite, kAECollapseAllID,gServerAddress, kAENoReply);
- {
- CTempDesc directObjectDesc;
- if (gAppleEventRouting == routeToDoc)
- fTwistDownDocument -> MakeObjectSpecifier(directObjectDesc, fTwistDownDocument -> GetSpecifierForm());
- else if (gAppleEventRouting == routeToView)
- fTwistDownView -> MakeObjectSpecifier(directObjectDesc, fTwistDownView -> GetSpecifierForm());
-
- theCollapseAllEvent -> WriteParameter(keyDirectObject, directObjectDesc);
- }
- fi.Success();
- }
- else // Recover
- {
- theCollapseAllEvent = (TAppleEvent *)FreeIfObject(theCollapseAllEvent);
- fi.ReSignal();
- }
-
- return theCollapseAllEvent;
-
- }
- //----------------------------------------------------------------------------------------
- // TCollapseAllCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TCollapseAllCommand::DoIt()
- {
-
- fTwistDownDocument -> CollapseAll();
- //just set fNumberOfCollapsedControls to fInitialNumberOfControls
- //and set fNumberOfExpandedControls to 0.
- fTwistDownView -> SetCantCollapseAll(); //Will cause the cCollapseAll command to be disabled.
-
- }
- //========================================================================================
- // CLASS TExpandElementCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TServerCommand
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TExpandElementCommand, Inherited);
- //----------------------------------------------------------------------------------------
- // TExpandElementCommand::TExpandElementCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TExpandElementCommand::TExpandElementCommand()
- {
- fTwistDownDocument = NULL;
- fTwistDownView = NULL;
- fElementToExpand = NULL;
-
- fOldNumberOfExpandedControls = 0;
- fOldNumberOfCollapsedControls = 0;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TExpandElementCommand::~TExpandElementCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TExpandElementCommand::~TExpandElementCommand()
- {
- fTwistDownDocument = NULL;
- fTwistDownView = NULL;
- fElementToExpand = NULL;
-
- fOldNumberOfExpandedControls = 0;
- fOldNumberOfCollapsedControls = 0;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TExpandElementCommand::IExpandElementCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TExpandElementCommand::IExpandElementCommand(TTwistDownDocument* twistDownDocument,
- TTwistDownElement* elementToExpand)
- {
-
- this -> IServerCommand(cExpandElement,fTwistDownDocument,kCantUndo, kDoesNotCauseChange,NULL);
-
- fTwistDownDocument = twistDownDocument;
- fTwistDownView = twistDownDocument -> fTwistDownView;
- fElementToExpand = elementToExpand;
-
- fOldNumberOfExpandedControls = fTwistDownView -> GetNumberOfExpandedControls();
- fOldNumberOfCollapsedControls = fTwistDownView -> GetNumberOfCollapsedControls();
- }
- //----------------------------------------------------------------------------------------
- // TExpandElementCommand::IExpandElementCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TExpandElementCommand::IExpandElementCommand(TTwistDownDocument* twistDownDocument,
- TTwistDownElement* elementToExpand, const AppleEvent& itsMessage,
- const AppleEvent& itsReply)
- {
- fSuspendTheEvent = TRUE; //For debugging fun and games, comment this out. Everything
- //will work fine until you encounter low memory conditions
- //and fail. Then all bets are off. Note that it must be set
- //before IServerCommand is called.
-
- this -> IServerCommand(cExpandElement,twistDownDocument,kCantUndo,kDoesNotCauseChange,NULL,
- itsMessage,itsReply);
-
- fTwistDownDocument = twistDownDocument;
- fTwistDownView = twistDownDocument -> fTwistDownView;
- fElementToExpand = elementToExpand;
-
- fOldNumberOfExpandedControls = fTwistDownView -> GetNumberOfExpandedControls();
- fOldNumberOfCollapsedControls = fTwistDownView -> GetNumberOfCollapsedControls();
- }
- //----------------------------------------------------------------------------------------
- // TExpandElementCommand::MakeAppleEvent: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment ACommandRes
- TAppleEvent* TExpandElementCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent*, theExpandElementEvent, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- theExpandElementEvent = new TAppleEvent;
- theExpandElementEvent -> IAppleEvent(kAETwistDownListsSuite, kAEExpandElementID,gServerAddress, kAENoReply);
- {
-
- CTempDesc targetObjectDesc;
- fElementToExpand -> MakeObjectSpecifier(targetObjectDesc, fElementToExpand -> GetSpecifierForm());
- theExpandElementEvent -> WriteParameter(keyDirectObject, targetObjectDesc);
-
- }
- fi.Success();
- }
- else // Recover
- {
- theExpandElementEvent = (TAppleEvent *)FreeIfObject(theExpandElementEvent);
- fi.ReSignal();
- }
-
- return theExpandElementEvent;
-
- }
- //----------------------------------------------------------------------------------------
- // TExpandElementCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TExpandElementCommand::DoIt()
- {
- FailInfo fi;
- Try(fi)
- {
- fTwistDownDocument -> ExpandElement(fElementToExpand);
- //I've got to increment fNumberOfExpandedControls here
- //and decrement fNumberOfCollapsedControls here to account for the
- //twistDownControl being expanded. All other controls will
- //take care of themselves.
- fTwistDownView -> IncrementNumberOfExpandedControls();
- fTwistDownView -> DecrementNumberOfCollapsedControls();
- fTwistDownView -> SetTheCouldFlags();
-
- fi.Success();
- }
- else
- {
- //If there is a failure, it most likely will occur because an out of memory condition
- //occurred while making a new control. To recover, we need to collapse the twistDownElement.
- fTwistDownDocument -> CollapseElement(fElementToExpand);
- fTwistDownView -> SetNumberOfExpandedControlsTo(fOldNumberOfExpandedControls);
- fTwistDownView -> SetNumberOfCollapsedControlsTo(fOldNumberOfCollapsedControls);
- fTwistDownView -> SetTheCouldFlags();
- fi.ReSignal();
- }
- }
- //========================================================================================
- // CLASS TCollapseElementCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TServerCommand
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TCollapseElementCommand, Inherited);
- //----------------------------------------------------------------------------------------
- // TCollapseElementCommand::TCollapseElementCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TCollapseElementCommand::TCollapseElementCommand()
- {
- fTwistDownDocument = NULL;
- fTwistDownView = NULL;
- fElementToCollapse = NULL;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TCollapseElementCommand::~TCollapseElementCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
- TCollapseElementCommand::~TCollapseElementCommand()
- {
- fTwistDownDocument = NULL;
- fTwistDownView = NULL;
- fElementToCollapse = NULL;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TCollapseElementCommand::ICollapseElementCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TCollapseElementCommand::ICollapseElementCommand(TTwistDownDocument* twistDownDocument,
- TTwistDownElement* elementToCollapse)
- {
- this -> IServerCommand(cCollapseElement,twistDownDocument,kCantUndo, kDoesNotCauseChange,NULL);
- fTwistDownDocument = twistDownDocument;
- fTwistDownView = twistDownDocument -> fTwistDownView;
- fElementToCollapse = elementToCollapse;
- }
- //----------------------------------------------------------------------------------------
- // TCollapseElementCommand::ICollapseElementCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- void TCollapseElementCommand::ICollapseElementCommand(TTwistDownDocument* twistDownDocument,
- TTwistDownElement* elementToCollapse, const AppleEvent& itsMessage,
- const AppleEvent& itsReply)
- {
- fSuspendTheEvent = TRUE; //For debugging fun and games, comment this out. Everything
- //will work fine until you encounter low memory conditions
- //and fail. Then all bets are off. Note that it must be set
- //before IServerCommand is called.
-
- this -> IServerCommand(cCollapseElement,twistDownDocument,kCantUndo,kDoesNotCauseChange,NULL,
- itsMessage,itsReply);
-
- fTwistDownDocument = twistDownDocument;
- fTwistDownView = twistDownDocument -> fTwistDownView;
- fElementToCollapse = elementToCollapse;
- }
- //----------------------------------------------------------------------------------------
- // TCollapseElementCommand::MakeAppleEvent: Scripting Support
- //----------------------------------------------------------------------------------------
- #pragma segment ACommandRes
- TAppleEvent* TCollapseElementCommand::MakeAppleEvent()
- {
-
- MAVolatileInit(TAppleEvent*, theCollapseElementEvent, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- theCollapseElementEvent = new TAppleEvent;
- theCollapseElementEvent -> IAppleEvent(kAETwistDownListsSuite,kAECollapseElementID,gServerAddress,kAENoReply);
- {
-
- CTempDesc directObjectDesc;
- fElementToCollapse -> MakeObjectSpecifier(directObjectDesc, fElementToCollapse -> GetSpecifierForm());
- theCollapseElementEvent -> WriteParameter(keyDirectObject, directObjectDesc);
-
- }
- fi.Success();
- }
- else // Recover
- {
- theCollapseElementEvent = (TAppleEvent *)FreeIfObject(theCollapseElementEvent);
- fi.ReSignal();
- }
-
- return theCollapseElementEvent;
-
- }
- //----------------------------------------------------------------------------------------
- // TCollapseElementCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
- void TCollapseElementCommand::DoIt()
- {
-
- fTwistDownDocument -> CollapseElement(fElementToCollapse);
- //I've got to increment fNumberOfCollapsedControls here
- //and decrement fNumberOfExpandedControls here to account for the
- //twistDownControl being collapsed. All other controls will take
- //care of themselves.
- fTwistDownView -> IncrementNumberOfCollapsedControls();
- fTwistDownView -> DecrementNumberOfExpandedControls();
- fTwistDownView -> SetTheCouldFlags();
-
- }
- #pragma segment Inline